package models

import (
	"common/rs"
	"common/uuid"
	"database/sql"
	"time"
)

const (
	RepairStatusWaiting   = 0 //等待修复
	RepairStatusRepairing = 1 //修复中
	RepairStatusError     = 2 //修复失败
)

type Repair struct {
	SegmentID  int64         `gorm:"column:segment_id;notNull;primaryKey;comment:segment_id" json:"segment_id"`
	StreamId   uuid.UUID     `gorm:"column:stream_id;type:BINARY(16);notNull;index:seg_idx;comment:流id" json:"stream_id"`
	Position   int           `gorm:"column:position;type:smallint;index:seg_idx;comment:segment位置" json:"position"`
	Status     int8          `gorm:"column:status;default:0;comment:修复状态,0等待修复，1在修复中，2修复失败" json:"status"`
	NodeId     uuid.NullUUID `gorm:"column:node_id;type:BINARY(16);comment:修复的节点" json:"node_id"`
	Retry      int           `gorm:"column:retry;notNull;default:0;comment:修复次数" json:"retry"`
	Redundancy rs.Rs         `gorm:"column:redundancy;type:int;notNull;default:0;comment:分片信息" json:"redundancy"`
	StartTime  sql.NullTime  `gorm:"column:start_time;type:time;comment:开始修复时间" json:"start_time"`
	CreatedAt  time.Time     `gorm:"column:created_at;type:time;notNull;default:CURRENT_TIMESTAMP" json:"created_at"`
	UpdatedAt  time.Time     `gorm:"column:updated_at;type:time;notNull;default:CURRENT_TIMESTAMP" json:"updated_at"`
}
